var dns = require('dns'),
    stats = require('../stats');

/**
 * Constructor for collecting DNS details
 */
var DnsStatCollector = exports.DnsStatCollector = function(config) {
  config.type = 'dns';
  this.resolve_type = config.resolve_type;

  stats.StatCollector.call(this, config);
};
process.inherits(DnsStatCollector, stats.StatCollector);

/**
 *
  */
DnsStatCollector.prototype.run = function(callback) {
  dns.resolve(this.hostname, this.resolve_type, function (err, addresses, ttl, cname) {
    if(err) {
      callback( {
        success: false,
        errmsg: err.message 
      });
    } else {
      callback( {
        success: true, 
        data: {
          addresses: addresses,
          ttl: ttl,
          cname: cname 
        }
      });
    }
  });
};
